package com.kfm.spring.dao.impl;

import com.kfm.spring.dao.IAccountDao;
import com.kfm.spring.model.Account;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.stereotype.Repository;

import java.util.List;


public class AccountDaoImpl2 extends JdbcDaoSupport implements IAccountDao {

    @Override
    public int save(Account account) {
        String sql = "insert into account(uid, money) values(?, ?)";
        return getJdbcTemplate().update(sql, account.getUid(), account.getMoney());
    }

    @Override
    public int update(Account account) {
        return 0;
    }

    @Override
    public int updateMoneyById(Integer id, Double money) {
        return 0;
    }

    @Override
    public Account findById(Integer id) {
        String sql = "select * from account where id = ?";
        return getJdbcTemplate().queryForObject(sql, new AccountDaoImpl.AccountRowMapper(), id);
    }

    @Override
    public List<Account> findAll() {
        String sql = "select * from account";
        return getJdbcTemplate().query(sql, new AccountDaoImpl.AccountRowMapper());
    }
}
